package cn.flying.cloud.tool.scheme.controller;

import javax.annotation.Resource;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.flying.cloud.base.common.vo.PageRequest;
import cn.flying.cloud.base.common.vo.PageResponse;
import cn.flying.cloud.base.common.vo.Rt;
import cn.flying.cloud.tool.scheme.entity.SchemeInfo;
import cn.flying.cloud.tool.scheme.service.SchemeInfoService;


/**
 * 数据库信息表 前端控制器
 *
 * @author: admin
 * @date: 2024-05-27 15:56:01
 * @version: 1.0
 */
@RestController
@RequestMapping("/tool/scheme")
public class SchemeInfoController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private SchemeInfoService schemeInfoService;

    /**
     * 分页查询数据库信息表数据
     *
     * @param request
     * @return
     */
    @PostMapping("page")
    public PageResponse page(@RequestBody PageRequest<SchemeInfo> request) {
        PageResponse response = schemeInfoService.getPageList(request);
        return response;
    }

    /**
     * 列表查询数据库信息表数据
     *
     * @param schemeInfo
     * @return
     */
    @PostMapping("list")
    public Rt list(@RequestBody SchemeInfo schemeInfo) {
        List<SchemeInfo> list = schemeInfoService.getList(schemeInfo);
        return Rt.success(list);
    }

    /**
     * 查询数据库信息表详情数据
     *
     * @param schemeInfo
     * @return
     */
    @PostMapping("detail")
    public Rt detail(SchemeInfo schemeInfo) {
        return Rt.success(schemeInfoService.getOneObj(schemeInfo));
    }

    /**
     * 根据主键ID查询数据库信息表详情数据
     *
     * @param id
     * @return
     */
    @PostMapping("getById")
    public Rt getById(Long id) {
        SchemeInfo schemeInfo = schemeInfoService.getById(id);
        return Rt.success(schemeInfo);
    }

    /**
     * 保存数据库信息表数据
     *
     * @param schemeInfo
     * @return
     */
    @PostMapping("save")
    public Rt save(@RequestBody SchemeInfo schemeInfo) {
        if (Objects.isNull(schemeInfo.getId())) {
            // 新增
            schemeInfoService.createObj(schemeInfo);
        } else {
            // 更新
            schemeInfoService.updateObj(schemeInfo);
        }
        return Rt.success("保存成功！");
    }

    /**
     * 删除数据库信息表数据
     *
     * @param schemeInfo
     * @return
     */
    @PostMapping("delete")
    public Rt delete(SchemeInfo schemeInfo) {
        schemeInfoService.deleteObj(schemeInfo);
        return Rt.success("删除成功！");
    }
}
